/* 排序
* 
* 本题:
    上面维护小根堆，下面维护大根堆，
    上面所有元素>=下面元素，下面的个数最多比上面多一个

*/

#define DEBUG
#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")

#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 1e5+10;

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
    #else
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif
    
    int T; cin >> T;
    while(T--)
    {
        int n, m; cin >> m >> n;
        printf("%d %d\n", m, (n+1)/2); // 数据集编号 中位数个数
        priority_queue<int> down;
        priority_queue<int, vector<int>, greater<int>> up;

        int cnt = 0; //换行输出计数
        for(int i = 1; i <= n; i++)
        {
            int x; cin >> x;
            if(down.empty() || x <= down.top()) down.push(x); //下面为空或x小于下方堆顶,则将x插入大根堆
            else up.push(x);

            //如果有偶数个数,上面和下面一样多,如果有奇数个数,则下面比上面多一个
            if(down.size() > up.size() + 1) up.push(down.top()), down.pop(); //下面推上面
            if(up.size() > down.size()) down.push(up.top()), up.pop(); //上面推下面

            if(i&1)
            {
                printf("%d ", down.top());
                if(++cnt % 10 == 0) puts("");
            }
        }
        if(cnt % 10) puts("");
    }
    return 0;
}